package top.continew.admin.jobfair.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;

import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.impl.BaseServiceImpl;
import top.continew.admin.jobfair.mapper.JobPositionResumeMapper;
import top.continew.admin.jobfair.model.entity.JobPositionResumeDO;
import top.continew.admin.jobfair.model.query.JobPositionResumeQuery;
import top.continew.admin.jobfair.model.req.JobPositionResumeReq;
import top.continew.admin.jobfair.model.resp.JobPositionResumeDetailResp;
import top.continew.admin.jobfair.model.resp.JobPositionResumeResp;
import top.continew.admin.jobfair.service.JobPositionResumeService;

/**
 * 岗位简历（投递）业务实现
 *
 * @author xiahaike
 * @since 2024/09/14 08:45
 */
@Service
@RequiredArgsConstructor
public class JobPositionResumeServiceImpl extends BaseServiceImpl<JobPositionResumeMapper, JobPositionResumeDO, JobPositionResumeResp, JobPositionResumeDetailResp, JobPositionResumeQuery, JobPositionResumeReq> implements JobPositionResumeService {

    @Resource
    private JobPositionResumeMapper jobPositionResumeMapper;

    @Override
    public boolean checkDuplicate(JobPositionResumeReq req) {
        QueryWrapper<JobPositionResumeDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("position_id", req.getPositionId());
        queryWrapper.eq("resume_id", req.getResumeId());
        return this.baseMapper.selectCount(queryWrapper) > 0;
    }

    @Override
    public PageResp<JobPositionResumeResp> myPage(JobPositionResumeQuery query, PageQuery pageQuery) {
        QueryWrapper<JobPositionResumeDO> queryWrapper = new QueryWrapper<>();
        IPage<JobPositionResumeResp> page = jobPositionResumeMapper.myPage(pageQuery.toPage(), queryWrapper, query.getUserId());
        return PageResp.build(page);
    }
}